<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>&lt;GRegex&gt;: </title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
<link rel="home" href="index.html" title="">
<link rel="up" href="ch01.html" title="GLib">
<link rel="prev" href="re50.html" title="&lt;GPtrArray&gt;">
<link rel="next" href="re52.html" title="&lt;%GLibRegexCompileFlags&gt;">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="re50.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="re52.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="id-1.1.52"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>&lt;GRegex&gt;</h2>
<p>&lt;GRegex&gt;</p>
</div>
<div class="refsect1">
<a name="id-1.1.52.2"></a><h2>Description</h2>
<p>The g_regex_*() functions implement regular
expression pattern matching using syntax and semantics similar to
Perl regular expression.
</p>
<p>Some functions accept a <em class="parameter"><code>start_position</code></em> argument, setting it differs
from just passing over a shortened string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span>
in the case of a pattern that begins with any kind of lookbehind assertion.
For example, consider the pattern "\Biss\B" which finds occurrences of "iss"
in the middle of words. ("\B" matches only if the current position in the
subject is not a word boundary.) When applied to the string "Mississipi"
from the fourth byte, namely "issipi", it does not match, because "\B" is
always false at the start of the subject, which is deemed to be a word
boundary. However, if the entire string is passed , but with
<em class="parameter"><code>start_position</code></em> set to 4, it finds the second occurrence of "iss" because
it is able to look behind the starting point to discover that it is
preceded by a letter.
</p>
<p>Note that, unless you set the <span class="type">G_REGEX_RAW</span> flag, all the strings passed
to these functions must be encoded in UTF-8. The lengths and the positions
inside the strings are in bytes and not in characters, so, for instance,
"\xc3\xa0" (i.e. "à") is two bytes long but it is treated as a
single character. If you set <span class="type">G_REGEX_RAW</span> the strings can be non-valid
UTF-8 strings and a byte is treated as a character, so "\xc3\xa0" is two
bytes and two characters long.
</p>
<p>When matching a pattern, "\n" matches only against a "\n" character in
the string, and "\r" matches only a "\r" character. To match any newline
sequence use "\R". This particular group matches either the two-character
sequence CR + LF ("\r\n"), or one of the single characters LF (linefeed,
U+000A, "\n"), VT vertical tab, U+000B, "\v"), FF (formfeed, U+000C, "\f"),
CR (carriage return, U+000D, "\r"), NEL (next line, U+0085), LS (line
separator, U+2028), or PS (paragraph separator, U+2029).
</p>
<p>The behaviour of the dot, circumflex, and dollar metacharacters are
affected by newline characters, the default is to recognize any newline
character (the same characters recognized by "\R"). This can be changed
with <span class="type">G_REGEX_NEWLINE_CR</span>, <span class="type">G_REGEX_NEWLINE_LF</span> and <span class="type">G_REGEX_NEWLINE_CRLF</span>
compile options, and with <span class="type">G_REGEX_MATCH_NEWLINE_ANY</span>,
<span class="type">G_REGEX_MATCH_NEWLINE_CR</span>, <span class="type">G_REGEX_MATCH_NEWLINE_LF</span> and
<span class="type">G_REGEX_MATCH_NEWLINE_CRLF</span> match options. These settings are also
relevant when compiling a pattern if <span class="type">G_REGEX_EXTENDED</span> is set, and an
unescaped "#" outside a character class is encountered. This indicates
a comment that lasts until after the next newline.
</p>
<p>When setting the <code class="constant">G_REGEX_JAVASCRIPT_COMPAT</code> flag, pattern syntax and pattern
matching is changed to be compatible with the way that regular expressions
work in JavaScript. More precisely, a lonely ']' character in the pattern
is a syntax error; the '\x' escape only allows 0 to 2 hexadecimal digits, and
you must use the '\u' escape sequence with 4 hex digits to specify a unicode
codepoint instead of '\x' or 'x{....}'. If '\x' or '\u' are not followed by
the specified number of hex digits, they match 'x' and 'u' literally; also
'\U' always matches 'U' instead of being an error in the pattern. Finally,
pattern matching is modified so that back references to an unset subpattern
group produces a match with the empty string instead of an error. See
pcreapi(3) for more information.
</p>
<p>Creating and manipulating the same <span class="type">GRegex</span> structure from different
threads is not a problem as <span class="type">GRegex</span> does not modify its internal
state between creation and destruction, on the other hand <span class="type">GMatchInfo</span>
is not threadsafe.
</p>
<p>The regular expressions low-level functionalities are obtained through
the excellent
[PCRE](http://www.pcre.org/)
library written by Philip Hazel.</p>
</div>
<div class="refsect1">
<a name="id-1.1.52.3"></a><h2>Functions</h2>
<div class="refsect2">
<a name="id-1.1.52.3.2"></a><h3>get-capture-count</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-capture-count self))
</pre></div>
<p>Returns the number of capturing subpatterns in the pattern.</p>
<div class="refsect3">
<a name="id-1.1.52.3.2.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.3"></a><h3>get-compile-flags</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-compile-flags self))
</pre></div>
<p>Returns the compile options that <em class="parameter"><code>regex</code></em> was created with.
</p>
<p>Depending on the version of PCRE that is used, this may or may not
include flags set by option expressions such as <code class="code">(?i)</code> found at the
top-level within the compiled pattern.</p>
<div class="refsect3">
<a name="id-1.1.52.3.3.5"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.4"></a><h3>get-has-cr-or-lf?</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-has-cr-or-lf? self))
</pre></div>
<p>Checks whether the pattern contains explicit CR or LF references.</p>
<div class="refsect3">
<a name="id-1.1.52.3.4.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.5"></a><h3>get-match-flags</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-match-flags self))
</pre></div>
<p>Returns the match options that <em class="parameter"><code>regex</code></em> was created with.</p>
<div class="refsect3">
<a name="id-1.1.52.3.5.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.6"></a><h3>get-max-backref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-max-backref self))
</pre></div>
<p>Returns the number of the highest back reference
in the pattern, or 0 if the pattern does not contain
back references.</p>
<div class="refsect3">
<a name="id-1.1.52.3.6.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.7"></a><h3>get-max-lookbehind</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-max-lookbehind self))
</pre></div>
<p>Gets the number of characters in the longest lookbehind assertion in the
pattern. This information is useful when doing multi-segment matching using
the partial matching facilities.</p>
<div class="refsect3">
<a name="id-1.1.52.3.7.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.8"></a><h3>get-pattern</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-pattern self))
</pre></div>
<p>Gets the pattern string associated with <em class="parameter"><code>regex</code></em>, i.e. a copy of
the string passed to <code class="function">g_regex_new()</code>.</p>
<div class="refsect3">
<a name="id-1.1.52.3.8.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.9"></a><h3>get-string-number</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:get-string-number self name))
</pre></div>
<p>Retrieves the number of the subexpression named <em class="parameter"><code>name</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.52.3.9.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p><span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>name</p></td>
<td class="parameter_description">
<p>name of the subexpression</p>
<p>Passed as <code class="code">name</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.10"></a><h3>match</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return match-info) (regex:match self string match-options))
</pre></div>
<p>Scans for a match in <em class="parameter"><code>string</code></em> for the pattern in <em class="parameter"><code>regex</code></em>.
The <em class="parameter"><code>match_options</code></em> are combined with the match options specified
when the <em class="parameter"><code>regex</code></em> structure was created, letting you have more
flexibility in reusing <span class="type">GRegex</span> structures.
</p>
<p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
</p>
<p>A <span class="type">GMatchInfo</span> structure, used to get information on the match,
is stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em>
is not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
i.e. you must free it regardless if regular expression actually matched.
</p>
<p>To retrieve all the non-overlapping matches of the pattern in
string you can use <code class="function">g_match_info_next()</code>.
</p>
<div class="informalexample"><pre class="programlisting">
static void
print_uppercase_words (const gchar *string)
{
  // Print all uppercase-only words.
  GRegex *regex;
  GMatchInfo *match_info;
 
  regex = g_regex_new ("[A-Z]+", 0, 0, NULL);
  g_regex_match (regex, string, 0, &amp;match_info);
  while (g_match_info_matches (match_info))
    {
      gchar *word = g_match_info_fetch (match_info, 0);
      g_print ("Found: %s\n", word);
      g_free (word);
      g_match_info_next (match_info, NULL);
    }
  g_match_info_free (match_info);
  g_regex_unref (regex);
}
</pre></div>

<p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
<div class="refsect3">
<a name="id-1.1.52.3.10.9"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
<p>Passed as <code class="code">match-info</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.11"></a><h3>match-all</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return match-info)
  (regex:match-all self string match-options))
</pre></div>
<p>Using the standard algorithm for regular expression matching only
the longest match in the string is retrieved. This function uses
a different algorithm so it can retrieve all the possible matches.
For more documentation see <code class="function">g_regex_match_all_full()</code>.
</p>
<p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
i.e. you must free it regardless if regular expression actually
matched.
</p>
<p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
<div class="refsect3">
<a name="id-1.1.52.3.11.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
<p>Passed as <code class="code">match-info</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.12"></a><h3>match-all-full</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return match-info)
  (regex:match-all-full self string start-position match-options))
</pre></div>
<p>Using the standard algorithm for regular expression matching only
the longest match in the <em class="parameter"><code>string</code></em> is retrieved, it is not possible
to obtain all the available matches. For instance matching
"&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;"
you get "&lt;a&gt; &lt;b&gt; &lt;c&gt;".
</p>
<p>This function uses a different algorithm (called DFA, i.e. deterministic
finite automaton), so it can retrieve all the possible matches, all
starting at the same point in the string. For instance matching
"&lt;a&gt; &lt;b&gt; &lt;c&gt;" against the pattern "&lt;.*&gt;;"
you would obtain three matches: "&lt;a&gt; &lt;b&gt; &lt;c&gt;",
"&lt;a&gt; &lt;b&gt;" and "&lt;a&gt;".
</p>
<p>The number of matched strings is retrieved using
<code class="function">g_match_info_get_match_count()</code>. To obtain the matched strings and
their position you can use, respectively, <code class="function">g_match_info_fetch()</code> and
<code class="function">g_match_info_fetch_pos()</code>. Note that the strings are returned in
reverse order of length; that is, the longest matching string is
given first.
</p>
<p>Note that the DFA algorithm is slower than the standard one and it
is not able to capture substrings, so backreferences do not work.
</p>
<p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
that begins with any kind of lookbehind assertion, such as "\b".
</p>
<p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
</p>
<p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
i.e. you must free it regardless if regular expression actually
matched.
</p>
<p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.</p>
<div class="refsect3">
<a name="id-1.1.52.3.12.11"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_len</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_position</p></td>
<td class="parameter_description">
<p>starting index of the string to match, in bytes</p>
<p>Passed as <code class="code">start-position</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
<p>Passed as <code class="code">match-info</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.13"></a><h3>match-full</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return match-info)
  (regex:match-full self string start-position match-options))
</pre></div>
<p>Scans for a match in <em class="parameter"><code>string</code></em> for the pattern in <em class="parameter"><code>regex</code></em>.
The <em class="parameter"><code>match_options</code></em> are combined with the match options specified
when the <em class="parameter"><code>regex</code></em> structure was created, letting you have more
flexibility in reusing <span class="type">GRegex</span> structures.
</p>
<p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
that begins with any kind of lookbehind assertion, such as "\b".
</p>
<p>Unless <code class="constant">G_REGEX_RAW</code> is specified in the options, <em class="parameter"><code>string</code></em> must be valid UTF-8.
</p>
<p>A <span class="type">GMatchInfo</span> structure, used to get information on the match, is
stored in <em class="parameter"><code>match_info</code></em> if not <code class="constant">NULL</code>. Note that if <em class="parameter"><code>match_info</code></em> is
not <code class="constant">NULL</code> then it is created even if the function returns <code class="constant">FALSE</code>,
i.e. you must free it regardless if regular expression actually
matched.
</p>
<p><em class="parameter"><code>string</code></em> is not copied and is used in <span class="type">GMatchInfo</span> internally. If
you use any <span class="type">GMatchInfo</span> method (except <code class="function">g_match_info_free()</code>) after
freeing or modifying <em class="parameter"><code>string</code></em> then the behaviour is undefined.
</p>
<p>To retrieve all the non-overlapping matches of the pattern in
string you can use <code class="function">g_match_info_next()</code>.
</p>
<div class="informalexample"><pre class="programlisting">
static void
print_uppercase_words (const gchar *string)
{
  // Print all uppercase-only words.
  GRegex *regex;
  GMatchInfo *match_info;
  GError *error = NULL;
  
  regex = g_regex_new ("[A-Z]+", 0, 0, NULL);
  g_regex_match_full (regex, string, -1, 0, 0, &amp;match_info, &amp;error);
  while (g_match_info_matches (match_info))
    {
      gchar *word = g_match_info_fetch (match_info, 0);
      g_print ("Found: %s\n", word);
      g_free (word);
      g_match_info_next (match_info, &amp;error);
    }
  g_match_info_free (match_info);
  g_regex_unref (regex);
  if (error != NULL)
    {
      g_printerr ("Error while matching: %s\n", error-&gt;message);
      g_error_free (error);
    }
}
</pre></div>
<div class="refsect3">
<a name="id-1.1.52.3.13.10"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure from <code class="function">g_regex_new()</code></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_len</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_position</p></td>
<td class="parameter_description">
<p>starting index of the string to match, in bytes</p>
<p>Passed as <code class="code">start-position</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_info</p></td>
<td class="parameter_description">
<p>pointer to location where to store
    the <span class="type">GMatchInfo</span>, or <code class="constant">NULL</code> if you do not need it</p>
<p>Passed as <code class="code">match-info</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.14"></a><h3>ref</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:ref self))
</pre></div>
<p>Increases reference count of <em class="parameter"><code>regex</code></em> by 1.</p>
<div class="refsect3">
<a name="id-1.1.52.3.14.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.15"></a><h3>replace</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (regex:replace self string start-position replacement match-options))
</pre></div>
<p>Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
replacement text. Backreferences of the form '\number' or
'\g&lt;number&gt;' in the replacement text are interpolated by the
number-th captured subexpression of the match, '\g&lt;name&gt;' refers
to the captured subexpression with the given name. '\0' refers
to the complete match, but '\0' followed by a number is the octal
representation of a character. To include a literal '\' in the
replacement, write '\\\\'.
</p>
<p>There are also escapes that changes the case of the following text:
</p>
<p>- \l: Convert to lower case the next character
- \u: Convert to upper case the next character
- \L: Convert to lower case till \E
- \U: Convert to upper case till \E
- \E: End case modification
</p>
<p>If you do not need to use backreferences use <code class="function">g_regex_replace_literal()</code>.
</p>
<p>The <em class="parameter"><code>replacement</code></em> string must be UTF-8 encoded even if <span class="type">G_REGEX_RAW</span> was
passed to <code class="function">g_regex_new()</code>. If you want to use not UTF-8 encoded strings
you can use <code class="function">g_regex_replace_literal()</code>.
</p>
<p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern that
begins with any kind of lookbehind assertion, such as "\b".</p>
<div class="refsect3">
<a name="id-1.1.52.3.15.9"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to perform matches against</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_len</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_position</p></td>
<td class="parameter_description">
<p>starting index of the string to match, in bytes</p>
<p>Passed as <code class="code">start-position</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>replacement</p></td>
<td class="parameter_description">
<p>text to replace each match with</p>
<p>Passed as <code class="code">replacement</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>options for the match</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.16"></a><h3>replace-literal</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (regex:replace-literal self string start-position replacement match-options))
</pre></div>
<p>Replaces all occurrences of the pattern in <em class="parameter"><code>regex</code></em> with the
replacement text. <em class="parameter"><code>replacement</code></em> is replaced literally, to
include backreferences use <code class="function">g_regex_replace()</code>.
</p>
<p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a
shortened string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the
case of a pattern that begins with any kind of lookbehind
assertion, such as "\b".</p>
<div class="refsect3">
<a name="id-1.1.52.3.16.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to perform matches against</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_len</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_position</p></td>
<td class="parameter_description">
<p>starting index of the string to match, in bytes</p>
<p>Passed as <code class="code">start-position</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>replacement</p></td>
<td class="parameter_description">
<p>text to replace each match with</p>
<p>Passed as <code class="code">replacement</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>options for the match</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.17"></a><h3>split</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:split self string match-options))
</pre></div>
<p>Breaks the string on the pattern, and returns an array of the tokens.
If the pattern contains capturing parentheses, then the text for each
of the substrings will also be returned. If the pattern does not match
anywhere in the string, then the whole string is returned as the first
token.
</p>
<p>As a special case, the result of splitting the empty string "" is an
empty vector, not a vector containing a single string. The reason for
this special case is that being able to represent an empty vector is
typically more useful than consistent handling of empty elements. If
you do need to represent empty elements, you'll need to check for the
empty string before calling this function.
</p>
<p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into separate
characters wherever it matches the empty string between characters.
For example splitting "ab c" using as a separator "\s*", you will get
"a", "b" and "c".</p>
<div class="refsect3">
<a name="id-1.1.52.3.17.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to split with the pattern</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match time option flags</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.18"></a><h3>split-full</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (regex:split-full self string start-position match-options max-tokens))
</pre></div>
<p>Breaks the string on the pattern, and returns an array of the tokens.
If the pattern contains capturing parentheses, then the text for each
of the substrings will also be returned. If the pattern does not match
anywhere in the string, then the whole string is returned as the first
token.
</p>
<p>As a special case, the result of splitting the empty string "" is an
empty vector, not a vector containing a single string. The reason for
this special case is that being able to represent an empty vector is
typically more useful than consistent handling of empty elements. If
you do need to represent empty elements, you'll need to check for the
empty string before calling this function.
</p>
<p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into separate
characters wherever it matches the empty string between characters.
For example splitting "ab c" using as a separator "\s*", you will get
"a", "b" and "c".
</p>
<p>Setting <em class="parameter"><code>start_position</code></em> differs from just passing over a shortened
string and setting <span class="type">G_REGEX_MATCH_NOTBOL</span> in the case of a pattern
that begins with any kind of lookbehind assertion, such as "\b".</p>
<div class="refsect3">
<a name="id-1.1.52.3.18.7"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span> structure</p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to split with the pattern</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string_len</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>start_position</p></td>
<td class="parameter_description">
<p>starting index of the string to match, in bytes</p>
<p>Passed as <code class="code">start-position</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match time option flags</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>max_tokens</p></td>
<td class="parameter_description">
<p>the maximum number of tokens to split <em class="parameter"><code>string</code></em> into.
  If this is less than 1, the string is split completely</p>
<p>Passed as <code class="code">max-tokens</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.19"></a><h3>unref</h3>
<div class="informalexample"><pre class="programlisting">(define-values () (regex:unref self))
</pre></div>
<p>Decreases reference count of <em class="parameter"><code>regex</code></em> by 1. When reference count drops
to zero, it frees all the memory associated with the regex structure.</p>
<div class="refsect3">
<a name="id-1.1.52.3.19.4"></a><h4>Parameters</h4>
<div class="informaltable"><table><tr>
<td class="parameter_name"><p>regex</p></td>
<td class="parameter_description">
<p>a <span class="type">GRegex</span></p>
<p>Passed as <code class="code">self</code></p>
</td>
</tr></table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.20"></a><h3>regex:new</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:new pattern compile-options match-options))
</pre></div>
<p>Undocumented</p>
<div class="refsect3">
<a name="id-1.1.52.3.20.4"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>pattern</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">pattern</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>compile_options</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">compile-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p></p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.21"></a><h3>regex:check-replacement</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return has-references) (regex:check-replacement replacement))
</pre></div>
<p>Checks whether <em class="parameter"><code>replacement</code></em> is a valid replacement string
(see <code class="function">g_regex_replace()</code>), i.e. that all escape sequences in
it are valid.
</p>
<p>If <em class="parameter"><code>has_references</code></em> is not <code class="constant">NULL</code> then <em class="parameter"><code>replacement</code></em> is checked
for pattern references. For instance, replacement text 'foo\n'
does not contain references and may be evaluated without information
about actual match, but '\0\1' (whole match followed by first
subpattern) requires valid <span class="type">GMatchInfo</span> object.</p>
<div class="refsect3">
<a name="id-1.1.52.3.21.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>replacement</p></td>
<td class="parameter_description">
<p>the replacement string</p>
<p>Passed as <code class="code">replacement</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>has_references</p></td>
<td class="parameter_description">
<p>location to store information about
  references in <em class="parameter"><code>replacement</code></em> or <code class="constant">NULL</code></p>
<p>Passed as <code class="code">has-references</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.22"></a><h3>regex:error-quark</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:error-quark))
</pre></div>
<p>Undocumented</p>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.23"></a><h3>regex:escape-nul</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:escape-nul string length))
</pre></div>
<p>Escapes the nul characters in <em class="parameter"><code>string</code></em> to "\x00".  It can be used
to compile a regex with embedded nul characters.
</p>
<p>For completeness, <em class="parameter"><code>length</code></em> can be -1 for a nul-terminated string.
In this case the output string will be of course equal to <em class="parameter"><code>string</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.52.3.23.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to escape</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em></p>
<p>Passed as <code class="code">length</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.24"></a><h3>regex:escape-string</h3>
<div class="informalexample"><pre class="programlisting">(define-values (%return) (regex:escape-string string))
</pre></div>
<p>Escapes the special characters used for regular expressions
in <em class="parameter"><code>string</code></em>, for instance "a.b*c" becomes "a\.b\*c". This
function is useful to dynamically generate regular expressions.
</p>
<p><em class="parameter"><code>string</code></em> can contain nul characters that are replaced with "\0",
in this case remember to specify the correct length of <em class="parameter"><code>string</code></em>
in <em class="parameter"><code>length</code></em>.</p>
<div class="refsect3">
<a name="id-1.1.52.3.24.5"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to escape</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>length</p></td>
<td class="parameter_description">
<p>the length of <em class="parameter"><code>string</code></em>, in bytes, or -1 if <em class="parameter"><code>string</code></em> is nul-terminated</p>
<p>Inferred from <code class="code">string</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.25"></a><h3>regex:match-simple?</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (regex:match-simple? pattern string compile-options match-options))
</pre></div>
<p>Scans for a match in <em class="parameter"><code>string</code></em> for <em class="parameter"><code>pattern</code></em>.
</p>
<p>This function is equivalent to <code class="function">g_regex_match()</code> but it does not
require to compile the pattern with <code class="function">g_regex_new()</code>, avoiding some
lines of code when you need just to do a match without extracting
substrings, capture counts, and so on.
</p>
<p>If this function is to be called on the same <em class="parameter"><code>pattern</code></em> more than
once, it's more efficient to compile the pattern once with
<code class="function">g_regex_new()</code> and then use <code class="function">g_regex_match()</code>.</p>
<div class="refsect3">
<a name="id-1.1.52.3.25.6"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>pattern</p></td>
<td class="parameter_description">
<p>the regular expression</p>
<p>Passed as <code class="code">pattern</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>compile_options</p></td>
<td class="parameter_description">
<p>compile options for the regular expression, or 0</p>
<p>Passed as <code class="code">compile-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options, or 0</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
<div class="refsect2">
<a name="id-1.1.52.3.26"></a><h3>regex:split-simple</h3>
<div class="informalexample"><pre class="programlisting">(define-values
  (%return)
  (regex:split-simple pattern string compile-options match-options))
</pre></div>
<p>Breaks the string on the pattern, and returns an array of
the tokens. If the pattern contains capturing parentheses,
then the text for each of the substrings will also be returned.
If the pattern does not match anywhere in the string, then the
whole string is returned as the first token.
</p>
<p>This function is equivalent to <code class="function">g_regex_split()</code> but it does
not require to compile the pattern with <code class="function">g_regex_new()</code>, avoiding
some lines of code when you need just to do a split without
extracting substrings, capture counts, and so on.
</p>
<p>If this function is to be called on the same <em class="parameter"><code>pattern</code></em> more than
once, it's more efficient to compile the pattern once with
<code class="function">g_regex_new()</code> and then use <code class="function">g_regex_split()</code>.
</p>
<p>As a special case, the result of splitting the empty string ""
is an empty vector, not a vector containing a single string.
The reason for this special case is that being able to represent
an empty vector is typically more useful than consistent handling
of empty elements. If you do need to represent empty elements,
you'll need to check for the empty string before calling this
function.
</p>
<p>A pattern that can match empty strings splits <em class="parameter"><code>string</code></em> into
separate characters wherever it matches the empty string between
characters. For example splitting "ab c" using as a separator
"\s*", you will get "a", "b" and "c".</p>
<div class="refsect3">
<a name="id-1.1.52.3.26.8"></a><h4>Parameters</h4>
<div class="informaltable"><table>
<tr>
<td class="parameter_name"><p>pattern</p></td>
<td class="parameter_description">
<p>the regular expression</p>
<p>Passed as <code class="code">pattern</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>string</p></td>
<td class="parameter_description">
<p>the string to scan for matches</p>
<p>Passed as <code class="code">string</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>compile_options</p></td>
<td class="parameter_description">
<p>compile options for the regular expression, or 0</p>
<p>Passed as <code class="code">compile-options</code></p>
</td>
</tr>
<tr>
<td class="parameter_name"><p>match_options</p></td>
<td class="parameter_description">
<p>match options, or 0</p>
<p>Passed as <code class="code">match-options</code></p>
</td>
</tr>
</table></div>
</div>
</div>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>
